package com.cy.pj.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cy.pj.common.vo.PageResult;
import com.cy.pj.exception.ServiceException;
import com.cy.pj.sys.dao.SysItemDao;
import com.cy.pj.sys.entity.SysItem;
import com.cy.pj.sys.service.SysItemService;

@Service
public class SysItemServiceImpl implements SysItemService{

	@Autowired
	private SysItemDao sysItemDao;
	
	@Override
	public PageResult<SysItem> findPageObjects(String itemName, Integer pageCurrent) {
		// 校验参数
		if(pageCurrent==0 || pageCurrent<1)
			throw new IllegalArgumentException("请输入正确的页码值");
		
		// 查询总数
		int rowCount = sysItemDao.getRowCount(itemName);
		if(rowCount==0)
			throw new ServiceException("没有用户信息");
		
		// 分页查询
		int pageSize = 3;
		int startIndex = (pageCurrent-1)*pageSize;
		List<SysItem> records=
				sysItemDao.findPageObjects(itemName, startIndex, pageSize);
		
		// 封装
		PageResult<SysItem> list = new PageResult<>();
		list.setPageCount( (rowCount-1)/pageSize+1 );
		list.setPageCurrent(pageCurrent);
		list.setPageSize(pageSize);
		list.setRecords(records);
		list.setRowCount(rowCount);
		
		return list;
	}



	
}











